script_enemy_main{

let phase=rand_int(0,3);
let direction=0;

let character="Midori";
let cutin=character;
let dispelled=0;
let spellcards=1;
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let frame=0; let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let GRboss=("\script\Images\CharacterSprites\Midori.png");

#include_function "script/Functions/HealthBarLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsMidori1.txt");

	LoadGraphic("\script\Images\CharacterSprites\Midori.png");

	SetLife(150);
	if(GetCommonData("Difficulty")==1){ SetLife(160); }
	if(GetCommonData("Difficulty")==2){ SetLife(145); }
	if(GetCommonData("Difficulty")==3){ SetLife(130); }
	if(GetCommonData("Difficulty")==4){ SetLife(125); }
	SetTimer(35);
	SetInvincibility(120);
	SetDamageRate(10,10); 
	SetEnemyMarker(true);
	MagicCircle(true);
	SetMovePosition02(cx,miny+100,50);

	SetCommonData("BossStartLife",GetEnemyLife);
	SetCommonData("FamiliarDestroyed",0);
	SetCommonData("LifeBarPresent",1);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(250,250,250,250);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=2; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

HealthBar();


if(time%200==0 && time>=60){
	if(GetPlayerX>minx+50 && GetPlayerX<maxx-50){
	SetMovePosition01(GetPlayerX+rand(-30,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX<=minx+50){
	SetMovePosition01(GetPlayerX+rand(15,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX>=maxx-50){
	SetMovePosition01(GetPlayerX-rand(15,30),rand(miny+60,miny+120),1.5);
	}
}


if(phase%4==0){ direction=1; }
if((phase+2)%4==0){ direction=-1; }
if(phase%2!=0){ direction=0; }


if(GetCommonData("Difficulty")==1){
	if((time+80)%160==0 && time>=60){
	let angle=GetAngleToPlayer;
		loop(17){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Midori - Nonspell 1 - Familiar.txt",GetX,GetY,0,0,[angle,direction]);
		angle+=360/17;
		}
	phase++;
	}
} //Easy

//=============================================================================================================

if(GetCommonData("Difficulty")==2){
	if((time+75)%150==0 && time>=60){
	let angle=GetAngleToPlayer;
		loop(20){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Midori - Nonspell 1 - Familiar.txt",GetX,GetY,0,0,[angle,direction]);
		angle+=360/20;
		}
	phase++;
	}
} //Normal

//=============================================================================================================

if(GetCommonData("Difficulty")==3){
	if((time+70)%140==0 && time>=60){
	let angle=GetAngleToPlayer;
		loop(20){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Midori - Nonspell 1 - Familiar.txt",GetX,GetY,0,0,[angle,direction]);
		angle+=360/20;
		}
	phase++;
	}
} //Hard

//=============================================================================================================

if(GetCommonData("Difficulty")==4){
	if((time+60)%120==0 && time>=60){
	let angle=GetAngleToPlayer;
		loop(22){
		CreateEnemyFromFile(GetCurrentScriptDirectory~"Midori - Nonspell 1 - Familiar.txt",GetX,GetY,0,0,[angle,direction]);
		angle+=360/22;
		}
	phase++;
	}
} //Lunatic

if(GetCommonData("FamiliarDestroyed")==1){ AddLife(-3); SetCommonData("FamiliarDestroyed",0); }


if(GetCommonDataDefault("FamiliarDestroyed",0)==1 && OnBomb==false){ AddLife(-25); SetCommonData("FamiliarDestroyed",0); }
if(GetCommonDataDefault("FamiliarDestroyed",0)==1 && OnBomb==true){ SetCommonData("FamiliarDestroyed",0); }


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/HealthBar.txt";
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }

	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	if(GetLife>0){ DrawGraphic(GetX,GetY); }
}
 
@Finalize{
}

}